package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.controller.request.ExhibitionPageRequest;
import com.example.springboot.entity.Exhibition;
import com.example.springboot.service.IExhibitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin  //解决跨域错误
@RestController
@RequestMapping("/exhibition")
//是rest风格的exhibitioncontroller
public class ExhibitionController {

    @Autowired
    IExhibitionService exhibitionService;

    //    ExhibitionPageRequest传入用户名和电话信息
    @GetMapping("/page")
    public Result page(ExhibitionPageRequest exhibitionPageRequest){
        //        返回数据 Result.success传入一个对象
        return Result.success(exhibitionService.page(exhibitionPageRequest));
    }

    @GetMapping("/userPage")
    public Result userPage(ExhibitionPageRequest exhibitionPageRequest){
        //        返回数据 Result.success传入一个对象
        return Result.success(exhibitionService.page(exhibitionPageRequest));

    }

//    post put get delete对应增改查删四类操作
    //    新增会员
    @PostMapping("/save")
    public Result save(@RequestBody Exhibition exhibition){
        exhibitionService.save(exhibition);
        return Result.success();
    }

//    更新会员信息
    @PutMapping("/update")
    public Result update(@RequestBody Exhibition exhibition){
        exhibitionService.update(exhibition);
        return Result.success();
    }

    //    获取用户列表
    @GetMapping("/list")
    public Result list(){
        //        返回数据
        List<Exhibition> exhibitions=exhibitionService.list();
//        System.out.println("exhibitions内容是"+exhibitions);
        return Result.success(exhibitions);

    }


//    根据ID更新用户信息
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Exhibition exhibition =exhibitionService.getById(id);
        return Result.success(exhibition);

    }

    //删除操作:
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        exhibitionService.deleteById(id);
        return Result.success();
    }



    /*
    最初是通过List返回所有数据,而建立Result后采用Result返回数据
    @GetMapping("/list")
    public List<Exhibition> listExhibitions(){
        return exhibitionService.listExhibitions();
    }
     */
}
